Skip to content

Textmate cooperation #4397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 11, 2020
Merged

Conversation

georgewfraser
Copy link
Contributor

@georgewfraser georgewfraser commented May 9, 2020

This PR tweaks the fallback TextMate scopes to make them more consistent with the existing grammar and other languages, and edits the builtin TextMate grammar to align with semantic coloring. Before is on the left, after is on the right:

Screen Shot 2020-05-10 at 1 45 51 PM

Use keyword.other for regular keywords instead of keyword. This is a really peculiar quirk of TextMate conventions, but virtually all TextMate grammars use keyword.other (colored blue in VSCode Dark+) for regular keywords and keyword.control (colored purple in VSCode Dark+) for control keywords. The TextMate scope keyword is colored like control keywords, not regular keywords. It may seem strange that the keyword scope is not the right fallback for the keyword semantic token, but TextMate has a long and weird history. Note how keywords change from purple back to blue (what they were before semantic coloring was added):

(1) Use punctuation.section.embedded for format specifiers. This aligns with how Typescript colors formatting directives:

Screen Shot 2020-05-09 at 10 54 01 AM

(2) Consistently use entity.name.type.* scopes for type names. Avoid using entity.name.* which gets colored like a keyword.

(3) Use Property instead of Member for fields. Property and Member are very similar, but if you look at the TextMate fallback scopes, it's clear that Member is intended for function-like-things (methods?) and Property is intended for variable-like-things.

(4) Color for as a regular keyword when it's part of impl Trait for Struct.

(5) Use variable.other.constant for constants instead of entity.name.constant. In the latest VSCode insiders, variable.other.constant has a subtly different color that differentiates constants from ordinary variables. It looks close to the green of types but it's not the same---it's a new color recently added to take advantage of semantic coloring.

I also made some minor changes that make the TextMate scopes better match the semantic scopes. The effect of this for the user is you observe less of a change when semantic coloring "activates". You can see the changes I made relative to the built-in TextMate grammar here:

https://github.com/rust-analyzer/rust-analyzer/pull/4397/files/a91d15c80c337dd1afb0eddd5eb048010d098ac7..97428b6d52d25f810dbd7d7a8d787740c58bfbd2#diff-6966c729b862f79f79bf7258eb3e0885

This was referenced May 9, 2020
@aloucks
Copy link
Contributor

aloucks commented May 10, 2020

The change to lifetime coloring is the first screenshot is worse. I definitely prefer it being different from types.

@@ -600,7 +600,7 @@
},
"core_types": {
"comment": "Built-in/core type",
"name": "storage.type.core.rust",
"name": "entity.name.type.core.rust",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will mean that builtin types no longer get any different syntax highlighting compared to other types, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that’s right. I’m open to changing these choices—the main goal of this PR is just to make the TextMate grammar and the semantic colors consistent with each other, and to fix anything that’s clearly just a mistake/accident inherited from TextMate.

@georgewfraser
Copy link
Contributor Author

georgewfraser commented May 10, 2020

I've discovered a few more subtle disagreements between TextMate and semantic coloring and fixed them:

  • as should be colored as a keyword (fixed TextMate)
  • in should be colored as a control keyword (fixed semantic coloring)
  • for should be colored as a regular keyword when it's part of impl Trait for Struct (fixed semantic coloring)

@georgewfraser georgewfraser force-pushed the textmate_cooperation branch from 257c2ab to 63b75a4 Compare May 10, 2020 20:15
@georgewfraser
Copy link
Contributor Author

(Rebased)

@georgewfraser
Copy link
Contributor Author

@aloucks Since changing lifetimes to look like types seems to be controversial, I undid that to keep this PR narrowly focused on harmonizing TextMate and semantic coloring.

@bjorn3 right now, TextMate is coloring builtins like keywords, semantic coloring is coloring them like types. Personally I think coloring them like types is better, but I'm happy to go with the consensus either way---we should just be consistent between TextMate and semantic coloring.

@georgewfraser
Copy link
Contributor Author

(Edited the description to show before-and-after more clearly)

@aloucks
Copy link
Contributor

aloucks commented May 10, 2020

I think & looks weird now that it's the same color as self (and presumable mut as well). I think & looks better uncolored/grey.

@georgewfraser
Copy link
Contributor Author

@aloucks Yeah I suppose that's a change as well. It does match the way rust is colored elsewhere, but in the spirit of "let's keep this PR focused on harmonization not change" I put that back.

@georgewfraser
Copy link
Contributor Author

Use punctuation.section.embedded for format specifiers is also technically a change, though I think it's such a no-brainer that I'm leaving it in for now. If anyone disagrees, I'm happy to take it out and make that a separate PR :)

@DJMcNab
Copy link
Contributor

DJMcNab commented May 11, 2020

It might be worth using member for fields which have function types or have Fn[Once/Mut]() bounds.
I think this matches the behaviour of the typescript server. Otherwise the described changes look excellent to me, although I haven't tested them

Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

I am still personally a huge anti-fan of having tmGrammar for Rust at all, (here's the grammar I use), but this is clearly a huge improvement in practice! Thanks @georgewfraser!

| T![while] => h | HighlightModifier::ControlFlow,
| T![while]
| T![in] => h | HighlightModifier::ControlFlow,
T![for] if !is_child_of_impl(element) => h | HighlightModifier::ControlFlow,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@bors
Copy link
Contributor

bors bot commented May 11, 2020

bors bot added a commit that referenced this pull request May 12, 2020
4436: Use .rust suffix on scopes r=matklad a=georgewfraser

This PR should have no effect on people using any of the default themes, but it is possible there are people with custom themes that rely on the .rust suffix on textmate scopes, which I neglected to use consistently in #4397.

Co-authored-by: George Fraser <[email protected]>
bors bot added a commit that referenced this pull request May 13, 2020
4400: Enhanced coloring r=georgewfraser a=georgewfraser

This PR builds on #4397 to enhance the existing syntax coloring. 

## Underline mutable variables

The textmate scope `markup.underline` underlines identifiers, which is a nice way to make mutable vars stand out:

<img width="327" alt="Screen Shot 2020-05-09 at 1 18 55 PM" src="https://user-images.githubusercontent.com/1369240/81484179-8bb47d80-91f8-11ea-997d-1dcffbe44aa7.png">

## Italicize static variables

The textmate scope `markup.italic` italicizes identifiers. Italic = static is a common convention in IDEs like IntelliJ:

<img width="288" alt="Screen Shot 2020-05-09 at 1 19 14 PM" src="https://user-images.githubusercontent.com/1369240/81484236-cd452880-91f8-11ea-8478-505ee49bc8b3.png">


Co-authored-by: George Fraser <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants